/**
 * Alibaba.com.cn Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package com.yongbao.common.enums;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Date;

/**
 * @author zhanghong
 * @version OrderTypeEnum.java, v 0.1 2024/3/30 00:24 下午 OrderTypeEnum Exp $$
 */
public enum OrderTypeEnum {
    /**
     *
     */
    WEEK_DISH(1, "周餐"),
    MONTH_DISH(2, "月餐"),
    ;

    private Integer code;
    private String desc;

    OrderTypeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static Pair<Date, Date> getDishRange(Integer code) {
        Date date = new Date();
        if (WEEK_DISH.getCode().equals(code)) {
            DateTime start = DateUtil.offsetDay(date, 1);
            DateTime end = DateUtil.offsetDay(start, 7);
            return Pair.of(DateUtil.beginOfDay(start), DateUtil.endOfDay(end));
        }
        if (MONTH_DISH.getCode().equals(code)) {
            DateTime start = DateUtil.offsetDay(date, 1);
            DateTime end = DateUtil.offsetDay(start, 30);
            return Pair.of(DateUtil.beginOfDay(start), DateUtil.endOfDay(end));
        }
        DateTime start = DateUtil.offsetDay(date, 1);
        DateTime end = DateUtil.offsetDay(start, 1);
        return Pair.of(DateUtil.beginOfDay(start), DateUtil.endOfDay(end));
    }
}
